const express = require("express");
const router = express.Router();
const { getStatic ,result} = require("../util/util");

/* GET home page. */
router.post("/", async (req, res, next) => {
	try {
		let downLoadUrl=req.body.url;
		if(!downLoadUrl){
			throw 'downLoadUrl参数不能为空';
		}
		let staticRes = await getStatic({
			url: downLoadUrl
		});
		let base64=staticRes.body.toString('base64')
		res.json(
			result({
				d: {
					base64,
					type:staticRes.type
				}
			})
		);
	} catch (err) {
		res.json(
            result({
                s: 0,
                m: err,
                data:''
            })
        );
	}
});

module.exports = router;
